<template>
  <div class="payment-method-selector">
    <div class="method-title">选择支付方式</div>
    <el-radio-group v-model="selectedMethod" @change="handleMethodChange">
      <el-radio value="wechat" class="method-option">
        <div class="method-content">
          <el-icon class="method-icon wechat-icon"><ChatDotRound /></el-icon>
          <span>微信支付</span>
        </div>
      </el-radio>
      <el-radio value="alipay" class="method-option">
        <div class="method-content">
          <el-icon class="method-icon alipay-icon"><Wallet /></el-icon>
          <span>支付宝</span>
        </div>
      </el-radio>
      <el-radio value="unionpay" class="method-option">
        <div class="method-content">
          <el-icon class="method-icon unionpay-icon"><CreditCard /></el-icon>
          <span>银联支付</span>
        </div>
      </el-radio>
    </el-radio-group>
  </div>
</template>

<script setup>
import { ref, watch } from 'vue'
import { ChatDotRound, Wallet, CreditCard } from '@element-plus/icons-vue'

// Props
const props = defineProps({
  modelValue: {
    type: String,
    default: 'wechat'
  }
})

// Emits
const emit = defineEmits(['update:modelValue', 'change'])

// 选中的支付方式
const selectedMethod = ref(props.modelValue)

// 监听外部值变化
watch(() => props.modelValue, (newValue) => {
  selectedMethod.value = newValue
})

// 处理支付方式变化
const handleMethodChange = (value) => {
  emit('update:modelValue', value)
  emit('change', value)
}
</script>

<style scoped>
.payment-method-selector {
  padding: 20px;
  border: 1px solid #e4e7ed;
  border-radius: 8px;
  background-color: #fff;
}

.method-title {
  font-size: 16px;
  font-weight: 600;
  color: #2c3e50;
  margin-bottom: 16px;
}

.el-radio-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.method-option {
  margin: 0;
  padding: 12px;
  border: 1px solid #e4e7ed;
  border-radius: 6px;
  transition: all 0.3s ease;
}

.method-option:hover {
  border-color: #409eff;
  background-color: #f0f9ff;
}

.method-option.is-checked {
  border-color: #409eff;
  background-color: #f0f9ff;
}

.method-content {
  display: flex;
  align-items: center;
  gap: 12px;
}

.method-icon {
  font-size: 24px;
}

.wechat-icon {
  color: #07c160;
}

.alipay-icon {
  color: #1677ff;
}

.unionpay-icon {
  color: #e74c3c;
}

.method-content span {
  font-size: 14px;
  font-weight: 500;
  color: #2c3e50;
}
</style>